# 多个变量复制
a = b = c = 1
print(a, b, c)

a, b, c = 2, 2.23, 'test of c'
print(a, b, c)

# 标准数据类型-6
# 不可变 Number String Tuple
# 可变 List Set Dictionary

# Number
a,b,c,d = 20, 5.5, True, 4+3j
# type()不会认为子类是一种父类类型
print(type(a), type(b), type(c), type(d))
# isinstance()会认为子类是一种父类类型
print(isinstance(a, int))

# 建类: type 和 isinstance 的区别
class A:
	pass

class B(A):
	pass

print('1', A)
print('2', B)

print(A())
print(B())

print(isinstance(A(), A))
print(isinstance(B(), A))

print(type(A()))
print(type(B()))

print(type(A()) == A)
print(type(B()) == A)
#----

print('\n3---')
print(issubclass(bool, int))
print(True == 1)
print(False == 0)
print(True + 1)
print(False + 10)
print(1 is True)
print(0 is False)
print('3 end---')


print('\n4---')
del a
# NameError: name 'a' is not defined
#print(a)

print(2 / 3)
print(2 // 3)
print(20 % 3)
print(2 ** 3)
print('4 end---')

print('\n5---List 列表')
# 列表中元素的类型可以不相同

list1 = [1, 2, 3, 4, 5]
list2 = [10, 20, 30, 40]

print(list1)
print(list1[0])
print(list1[1:3])
print(list1[2:])
# 返回 []
print(list1[2:0])
print(list1[2:-1])
# 不会越界
print(list1[2:100])

print(list2 * 2)
print(list2 + list1)

# 改变列表元素
list1[2] = 999
print(list1)

list2[3:] = []
print(list2)

# append
print(list1.append('a'))
print(list1)

# pop 弹出末尾的元素（最右边）
list2.pop()
print(list2)

print(list1[0:4:2])
# 第二个元素为空
print(list1[0::2])

print('5 end---')

print('\n6---Tuple（元组）')
tuple1 = ()
print(tuple1)

tuple1 = (1, 2, 3)
print(tuple1)

tuple1 = (1, "2", '3', ['a', 'b'], (6,7,8))
print(tuple1)

print(tuple1[2])
print(tuple1[2:])
print(tuple1[-1])
print(tuple1[-2])

# 元组的元素不可改变
# TypeError: 'tuple' object does not support item assignment
#tuple1[0] = 999
print('6 end---')


print('\n7---Set（集合）')
# 注意，这不是空set，而是字典！
set1 = {}
print(set1)
print(type(set1)) # <class 'dict'>

set1 = set()
print(set1)
print(type(set1)) # <class 'set'>

set1 = {1,2,3}
print(set1)

set1 = set("abc")
print(set1) # {'b', 'c', 'a'} 而不是 一个元素"abc"
# 集合不支持索引
# TypeError: 'set' object does not support indexing
#print(set1[0])
#print(set1[1])
#print(set1[2])

print('a' in set1)
print('ab' in set1)

print('set操作：')
set1 = set('abcdefg')
set2 = set('efghijk')
print(set1 | set2)
print(set1 - set2)
print(set1 & set2)
print(set1 ^ set2)

print('7 end---')

print('\n8---Dictionary（字典）')
# 键(key)必须使用不可变类型。
dict1 = {}
print(dict1)

dict1['one'] = "1-菜鸟教程"
dict1[2] = '2-菜鸟工具'
print(dict1)
print(dict1.keys())
print(dict1.values())
print(dict1[2])

dict1 = {'name':'runoob', 'code':1, 'site': 'www.runoob.com'}
print(dict1)
print(dict1['code'])

# 构造函数 dict() 可以直接从键值对序列中构建字典
dict1 = dict([('pm1', 'zibin.qiu'), ('pm2', 'yanfang.wang'), \
	('tl', 'junhui.he')])
print(dict1)
print(dict1.values())
print(type(dict1.values()))
dict1.clear()
print(dict1)

# 元组做键值
dict1 = {(80,90):'cn'}
print(dict1)
print(dict1.keys())
print(dict1.values())

print('8 end---')

print('\n9---数据类型转换')
# 1、int(x [,base])
# 1)若 x 为纯数字，则不能有 base 参数，否则报错；其作用为对入参 x 取整
# 2)若 x 为 str，则 base 可略可有。
print(int('123'))
# error
#print(int('123', 2))
print(int('123', 8))
print(int('123', 16)) # 291
print(int('abc', 16)) # 2748
print(int(1.1)) # 1

# float(x)
print(float(1))
print(float(112))
print(float(-123.6))
print(float('123'))

# complex([real[, imag]])
# 创建一个复数
print(complex(1, 2))
print(complex(1))
print(complex("1"))
print(complex("1+2j"))
# 前后不能有空格
# ValueError: complex() arg is a malformed string
#print(complex("1 + 2j"))
#print(complex("1+ 2j"))
#print(complex("1 +2j"))

print('9 end---')


print('\n10---数据类型转换')
# str(x)
print("str(x):")
print(str(123))
print(str(123.321))
print(str('abc'))
print(str('def ghi'))
print(str(['a', 1]))
print(str({'key1':'val1', 2: 'val2'}))
print(str(('1a', 22, 33.33)))

# repr(x)
print('repr(x):')
s = 'abc'
print(s)
print(repr(s))

dict = {'key1':'va11', 'key2':'val2'}
print(dict)
print(repr(dict))

tpl = (1,2,3,4,5)
print(tpl)
print(repr(tpl))

s2 = '1 + 2'
print(s2)
print(repr(s2))

# eval(str)
# 用来执行一个字符串表达式，并返回表达式的值
print("eval(str)")
print(eval('1 + 100'))

int2047 = 2047
print(eval('int2047 * 2'))
print(eval('int2047 + 1000'))

str1 = '[1,2,3,4,"a","b"]'
print(str1)
list1 = eval(str1)
print(list1)

#a = input("请输入：")
#print(eval(a))

# 多个数据 英文逗号 隔开
#c,d = eval(input("请输入c、d："))
#print(c)
#print(d)

# tuple( iterable )
# 将可迭代系列（如字符串、列表）转换为元组
print('tuple( iterable ):')

tpl1 = tuple('abc')
print(tpl1)
tpl1 = tuple("cde")
print(tpl1)

list2 = [1,2,3,4]
tpl2 = tuple(list2)
print(tpl2)

# 集合转元组
set1 = {"123", 'abc', 123.444, 555}
print(type(set1))
print(tuple(set1))

# list( seq )
print("list( seq ):")
print(list("kmd"))
print(list((1,2,3,4,5,9,8,76)))

# 返回一个冻结的集合
# 冻结后集合不能再添加或删除任何元素
frset = frozenset('1bd')
print(type(frset))
print(frset)

frset = frozenset(["asd", '123', 555.666])
print(type(frset))
print(frset)

frset = frozenset()
print(type(frset))
print(frset)

# chr(i)
# 返回值是当前整数对应的 ASCII 字符
print('chr(i):')
print(chr(1), chr(10), chr(100), chr(100 - 26))
# 输出 256，啥也没了
#print(chr(256)
# SyntaxError: invalid syntax
#print(chr(257)
#print(chr(1000)

print(chr(0x61)) # a
print(chr(0x65)) # e

print(chr(0x61 - 26)) # G
print(chr(0x65 - 26)) # K

# ord(c)
# 是 chr() 函数（对于8位的ASCII字符串）或 unichr() 函数（对于Unicode对象）的配对函数
# 返回对应的 ASCII 数值，或者 Unicode 数值
print('ord(c):')
print(ord('a')) # 97
print(ord('A')) # 65
print(ord('中')) # 20013
print(ord('间')) # 38388

# hex(x)
# 将一个整数转换为一个十六进制字符串
print('hex(x):')
print(hex(123))
print(hex(123321123321))

# oct(x)
print('oct(x):')
print(oct(123))
print(oct(123321123321))


print('10 end---')